package player;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import commons.Manager;
import commons.exceptions.ProcessException;

public class CheckPlaying extends Thread {

	java.lang.Process proc;
	Manager parent;
	String path;
	boolean running;
	
	CheckPlaying(Manager parent, java.lang.Process proc){
		this.proc = proc;
		this.parent=parent;
		running=true;
	}
	
	public void run(){
		try {
		System.out.println("Debut de la lecture");
		BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
		String line;
			while((line=reader.readLine())!=null && running){
				String[] table=line.split("\\s+");
				if(table[0].equals("end")){
					System.out.println("Fin de lecture");
					parent.end();
					break;
				}
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
				}
			}
		} catch (IOException | ProcessException e) {
		}
	}
	
	public void stopRunning(){
		this.running=false;
	}
}
